#! /bin/sh
##
## Copyright (C) by Argonne National Laboratory
##     See COPYRIGHT in top-level directory
##

# Run some of the tests.  If any arguments are provided, pass them to the
# test programs.
#
# -mvhome is needed for the ANL SP, and is ignored by others
args=@MPIRUNARGS@
device=@DEVICE@
top_srcdir=@top_srcdir@
srcdir=@srcdir@
MPICH_VERSION=@MPICH_VERSION@
STOPFILE=$HOME/.stopmpichtests
mpirun=${MPIRUN:-"@MPIRUN@"}
MAKE="@MAKE@"
FILENAME=test
#
# Load basic procedures
. ${top_srcdir}/runbase
#
# Set mpirun to the name/path of the mpirun program
FindMPIRUN
#
#
test_mpi2=@HAS_MPI2@
runtests=1
quiet=0
makeeach=0
writesummaryfile=no
MAKE="@MAKE@"
for arg in "$@" ; do
    case $arg in 
	-checkonly )
	runtests=0
	;;
        -margs=*)
	margs=`echo $arg | sed 's/-margs=//'`
	args="$args $margs"
	;;
	-summaryfile=*)
	writesummaryfile=yes
	summaryfile=`echo A$arg | sed 's/A-summaryfile=//'`
	;;
	-small)
	makeeach=1
	;;
	-fname=*)
	FILENAME=`echo $arg|sed 's/-*fname=//'`
	;;
	-quiet)
	shift
	quiet=1
	;;
	-help|-u)
	echo "runtests [-checkonly] [-margs='...']"
	echo "run tests in this directory.  If -checkonly set, just run"
	echo "the differences check (do NO rerun the test programs)."
	echo "If -margs is used, these options are passed to mpirun."
	echo "If -small is used, the examples are built, run, and deleted."
	exit 1
	;;
	*)
	if test -n "$arg" ; then
   	    echo "runtests: Unknown argument ($arg)"
	    exit 1
        fi
	;;
    esac
done

# If the programs are not available, run make.
if [ ! -x simple -a $makeeach = 0 -a $runtests = 1 ] ; then
    $MAKE default
fi

testfiles=""
if [ $runtests = 1 ] ; then


RunTest simple 4 "**** Testing simple.c ****" "-fname $FILENAME"

RunTest async 4 "**** Testing async.c ****" "-fname $FILENAME"

RunTest atomicity 4 "**** Testing atomicity.out ****" "-fname $FILENAME"

RunTest coll_test 4 "**** Testing coll_test.out ****" "-fname $FILENAME"

RunTest excl 4 "**** Testing excl.c ****" "-fname $FILENAME"

RunTest file_info 4 "**** Testing file_info.c ****" "-fname $FILENAME"

RunTest i_noncontig 2 "**** Testing i_noncontig.c ****" "-fname $FILENAME"

RunTest noncontig 2 "**** Testing noncontig.c ****" "-fname $FILENAME"

RunTest noncontig_coll 2 "**** Testing noncontig_coll.c ****" "-fname $FILENAME"

RunTest noncontig_coll2 4 "**** Testing noncontig_coll2.c ****" "-fname $FILENAME"

RunTest misc 4 "**** Testing misc.c ****" "-fname $FILENAME"

RunTest shared_fp 4 "**** Testing shared_fp.c ****" "-fname $FILENAME"

RunTest split_coll 4 "**** Testing split_coll.c ****" "-fname $FILENAME"

RunTest psimple 4 "**** Testing psimple.c ****" "-fname $FILENAME"

RunTest error 1 "**** Testing error.c ****" "-fname $FILENAME"

RunTest status 1 "**** Testing status.c ****" "-fname $FILENAME"

#
# Run Fortran tests ONLY if Fortran available
if [ @HAS_FORTRAN@ = 1 ] ; then 
    RunTest fmisc 4 "**** Testing fmisc.f ****" "-fname $FILENAME"

    RunTest fcoll_test 4 "**** Testing fcoll_test.f ****" "-fname $FILENAME"

    RunTest pfcoll_test 4 "**** Testing pfcoll_test.f ****" "-fname $FILENAME"
fi

else
    # Just run checks
    testfiles=`echo *.out`
fi

echo '*** Checking for differences from expected output ***'
CheckAllOutput context.diff
exit 0



